﻿@page
@model AspnetRun.Web.Pages.Product.IndexModel

@{
    ViewData["Title"] = "Index";
}

<h1>Product List</h1>

<form method="get">
    <div class="form-group">
        <div class="input-group">
            <input type="search" class="form-control" asp-for="SearchTerm" />
            <span class="input-group-btn">
                <button class="btn btn-default">
                    Search
                </button>
            </span>
        </div>
    </div>
</form>

<p>
    <a asp-page="Create">Create New</a>
</p>

<table class="table table-hover">
    <thead>
        <tr>
            <th scope="col">Id</th>
            <th scope="col">Name</th>
            <th scope="col">UnitPrice</th>
            <th scope="col">Category</th>
            <th scope="col">Action</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var product in Model.ProductList)
        {
            <tr>
                <th scope="row">@product.Id</th>
                <td>@product.ProductName</td>
                <td>@product.UnitPrice</td>
                <td>@product.Category.CategoryName</td>
                <td>
                    <a class="btn"
                       asp-page="./Details"
                       asp-route-productId="@product.Id">
                        Details
                    </a>
                    <a class="btn"
                       asp-page="./Edit"
                       asp-route-productId="@product.Id">
                        Edit
                    </a>
                    <a class="btn"
                       asp-page="./Delete"
                       asp-route-productId="@product.Id">
                        Delete
                    </a>
                </td>
            </tr>
        }
    </tbody>
</table>
